#include "updater.h"
#include "server.h"

Updater::Updater(QObject *parent) : QObject(parent)
{
  server = new Server();
  connect(server, SIGNAL(stateChanged(int)), this, SIGNAL(stateChanged(int)));
}

void Updater::setDownloadPath(const QString &path)
{
  downPath = path;

  QDir dir;
  dir.mkpath(downPath);
}

void Updater::setRootPath(const QString &path)
{
    rootPath = path;
}

bool Updater::loadInstalledInfo(const QString &path)
{
    return pack.load(path, true);
}

void Updater::setServerInfo(const ServerInfo &info)
{
  server->setInfo(info);
}

bool Updater::connectServer()
{
  return server->connectServer();
}

int Updater::downloadVersion(const QString &path, const QString &name)
{
  if (!server->connected())
    return 0;

  int ok = server->getFile(path, downPath, name);

  if (ok)
      pack.load(downPath + "/" + name, false);

  return ok;
}
